# -*- coding:utf-8 -*-
import serial
import time
import struct
#设置串口、波特率以及发送数据间隔
ser = serial.Serial("/dev/ttyUSB3",9600,timeout=0.01) 
ser.flushInput()



GetStatu = bytearray()
#0xbb
GetStatu.append(187)
#0x55
GetStatu.append(85)
i=1
flag=0
# while i<=3:
# flag=0
GetStatu = struct.pack("BBBBBBBBB",0xaa,0x55,0x03,1,0,0,0,0,0)
ser.write(GetStatu)
ser.flush() # 等待所有数据写出  
time.sleep(1)
if ser.inWaiting() > 0:
    data = ser.readline()
    print(data)
    if data != "":
        if data[0]==187 and data[1]==85 and data[2]==i:
            # 收到状态回复
            print(data)
            flag=1
    # if flag==1:
    #     i+=1
    # else:
    #     break